from PySide6.QtWidgets import QDialog, QVBoxLayout, QTextEdit, QPushButton


class LogDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("Log Viewer")
        self.resize(600, 350)

        # 创建布局
        layout = QVBoxLayout()

        # 创建文本区域并设置为只读
        self.text_edit = QTextEdit(self)
        self.text_edit.setReadOnly(True)
        layout.addWidget(self.text_edit)

        # 创建关闭按钮
        close_button = QPushButton("Close", self)
        close_button.clicked.connect(self.accept)
        layout.addWidget(close_button)

        # 设置布局
        self.setLayout(layout)

    def add_log_entry(self, log_entry):
        """ 添加新的日志条目 """
        self.text_edit.append(log_entry)